<?php


abstract class BaseAteneareferencia extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $motivo_ref;


	
	protected $fecha;


	
	protected $numero_consulta;


	
	protected $tipo_referencia;


	
	protected $referido_id;


	
	protected $recomendaciones;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getMotivoRef()
	{

		return $this->motivo_ref;
	}

	
	public function getFecha($format = 'Y-m-d')
	{

		if ($this->fecha === null || $this->fecha === '') {
			return null;
		} elseif (!is_int($this->fecha)) {
						$ts = strtotime($this->fecha);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha] as date/time value: " . var_export($this->fecha, true));
			}
		} else {
			$ts = $this->fecha;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getNumeroConsulta()
	{

		return $this->numero_consulta;
	}

	
	public function getTipoReferencia()
	{

		return $this->tipo_referencia;
	}

	
	public function getReferidoId()
	{

		return $this->referido_id;
	}

	
	public function getRecomendaciones()
	{

		return $this->recomendaciones;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = AteneareferenciaPeer::ID;
		}

	} 
	
	public function setMotivoRef($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->motivo_ref !== $v) {
			$this->motivo_ref = $v;
			$this->modifiedColumns[] = AteneareferenciaPeer::MOTIVO_REF;
		}

	} 
	
	public function setFecha($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha !== $ts) {
			$this->fecha = $ts;
			$this->modifiedColumns[] = AteneareferenciaPeer::FECHA;
		}

	} 
	
	public function setNumeroConsulta($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->numero_consulta !== $v) {
			$this->numero_consulta = $v;
			$this->modifiedColumns[] = AteneareferenciaPeer::NUMERO_CONSULTA;
		}

	} 
	
	public function setTipoReferencia($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->tipo_referencia !== $v) {
			$this->tipo_referencia = $v;
			$this->modifiedColumns[] = AteneareferenciaPeer::TIPO_REFERENCIA;
		}

	} 
	
	public function setReferidoId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->referido_id !== $v) {
			$this->referido_id = $v;
			$this->modifiedColumns[] = AteneareferenciaPeer::REFERIDO_ID;
		}

	} 
	
	public function setRecomendaciones($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->recomendaciones !== $v) {
			$this->recomendaciones = $v;
			$this->modifiedColumns[] = AteneareferenciaPeer::RECOMENDACIONES;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->motivo_ref = $rs->getString($startcol + 1);

			$this->fecha = $rs->getDate($startcol + 2, null);

			$this->numero_consulta = $rs->getString($startcol + 3);

			$this->tipo_referencia = $rs->getString($startcol + 4);

			$this->referido_id = $rs->getInt($startcol + 5);

			$this->recomendaciones = $rs->getString($startcol + 6);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 7; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Ateneareferencia object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(AteneareferenciaPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			AteneareferenciaPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(AteneareferenciaPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = AteneareferenciaPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += AteneareferenciaPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = AteneareferenciaPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = AteneareferenciaPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getMotivoRef();
				break;
			case 2:
				return $this->getFecha();
				break;
			case 3:
				return $this->getNumeroConsulta();
				break;
			case 4:
				return $this->getTipoReferencia();
				break;
			case 5:
				return $this->getReferidoId();
				break;
			case 6:
				return $this->getRecomendaciones();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = AteneareferenciaPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getMotivoRef(),
			$keys[2] => $this->getFecha(),
			$keys[3] => $this->getNumeroConsulta(),
			$keys[4] => $this->getTipoReferencia(),
			$keys[5] => $this->getReferidoId(),
			$keys[6] => $this->getRecomendaciones(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = AteneareferenciaPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setMotivoRef($value);
				break;
			case 2:
				$this->setFecha($value);
				break;
			case 3:
				$this->setNumeroConsulta($value);
				break;
			case 4:
				$this->setTipoReferencia($value);
				break;
			case 5:
				$this->setReferidoId($value);
				break;
			case 6:
				$this->setRecomendaciones($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = AteneareferenciaPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setMotivoRef($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setFecha($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setNumeroConsulta($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setTipoReferencia($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setReferidoId($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setRecomendaciones($arr[$keys[6]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(AteneareferenciaPeer::DATABASE_NAME);

		if ($this->isColumnModified(AteneareferenciaPeer::ID)) $criteria->add(AteneareferenciaPeer::ID, $this->id);
		if ($this->isColumnModified(AteneareferenciaPeer::MOTIVO_REF)) $criteria->add(AteneareferenciaPeer::MOTIVO_REF, $this->motivo_ref);
		if ($this->isColumnModified(AteneareferenciaPeer::FECHA)) $criteria->add(AteneareferenciaPeer::FECHA, $this->fecha);
		if ($this->isColumnModified(AteneareferenciaPeer::NUMERO_CONSULTA)) $criteria->add(AteneareferenciaPeer::NUMERO_CONSULTA, $this->numero_consulta);
		if ($this->isColumnModified(AteneareferenciaPeer::TIPO_REFERENCIA)) $criteria->add(AteneareferenciaPeer::TIPO_REFERENCIA, $this->tipo_referencia);
		if ($this->isColumnModified(AteneareferenciaPeer::REFERIDO_ID)) $criteria->add(AteneareferenciaPeer::REFERIDO_ID, $this->referido_id);
		if ($this->isColumnModified(AteneareferenciaPeer::RECOMENDACIONES)) $criteria->add(AteneareferenciaPeer::RECOMENDACIONES, $this->recomendaciones);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(AteneareferenciaPeer::DATABASE_NAME);

		$criteria->add(AteneareferenciaPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setMotivoRef($this->motivo_ref);

		$copyObj->setFecha($this->fecha);

		$copyObj->setNumeroConsulta($this->numero_consulta);

		$copyObj->setTipoReferencia($this->tipo_referencia);

		$copyObj->setReferidoId($this->referido_id);

		$copyObj->setRecomendaciones($this->recomendaciones);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new AteneareferenciaPeer();
		}
		return self::$peer;
	}

} 